import {DataRouter} from "../frame/dataSource/DataRouter";
import {TransData} from "../frame/dataSource/DataModel";
import {EnterType, TriggerFactory} from "../frame/TriggerFactory";
import {CodeUtil} from "../frame/codeAdapter/CodeUtil";
import {UnitModel} from "../frame/apiModel/adapterModel/model3/UnitModel";
import {PlayerModel} from "../frame/apiModel/adapterModel/model4/PlayerModel";
import {UnitController} from "../controller/UnitController";
import {RectModel} from "../frame/apiModel/adapterModel/model2/RectModel";

export function transTrigger() {
    const callback = (value: TransData) => {
        const start = value.tp_start;

        const transCallBack = function (this: void, rect: RectModel, transUnit: UnitModel, player: PlayerModel) {
            const transData = DataRouter.getTransDataByStart(rect.nikeName);
            if (transData) {
                const conditionIds = transData.condition;
                let conditionIdArr = CodeUtil.getArrBySplit(conditionIds);
                // todo 传送表默认条件后续设计
                // let bCheck = TaskController.getInstance().checkConditions(conditionIdArr, '', player);
                const bCheck = true;
                if (bCheck) {
                    UnitController.getInstance().useTransData([transUnit], transData);
                } else {
                    return;
                }
            }
        }
        if (start) {
            TriggerFactory.getInstance().registerUnitEnterRect(start, EnterType.trans, transCallBack)
        }
    }
    DataRouter.mapAllTransData(callback);
}